package com.jdk.demo.fileChannel.read;

import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Test2_5 {

	// 验证read方法从通道读取的数据大于缓冲区容量
	public static void main(String[] args) throws Exception {
		FileInputStream fisRef = new FileInputStream("b.txt");
		FileChannel fileChannel = fisRef.getChannel();
		
		ByteBuffer bytebuffer = ByteBuffer.allocate(3);
		fileChannel.read(bytebuffer);
		
		bytebuffer.rewind();
		for (int i = 0; i < bytebuffer.limit(); i++) {
			// 输出abc
			System.out.print((char)bytebuffer.get(i));
		}
		fileChannel.close();
		fisRef.close();
	}
	
}
